<template>
  <div class="group-prize-container">
    <div class="group-prize-total">已有<span class="num">{{total}}</span>人中奖</div>
    <div class="group-prize-list">
      <van-list
        v-model="loading"
        :finished="finished"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        finished-text=""
        @load="onLoad"
        :immediate-check="false">
        <div class="item" v-for="(item,index) in list" :key="index">
          <div class="item-img">
            <img :src="item.avatar" alt="" mode="scaleToFill">
          </div>
          <div class="item-name">{{item.nickname}}</div>
        </div>
      </van-list>
    </div>
    <div class="btn-box" v-if="is_show_reward_menu==1">
      <div class="btn btn-prize" @click="JumpName('order-detail',{id:order_id})">我的奖品</div>
    </div>
  </div>
</template>

<script>
import { groupRewardLog } from '@/api/item/activity'

import Vue from 'vue'
export default Vue.extend({
  data() {
    return {
      order_id: '',
      group_shopping_id: '',
      list: [],
      total: '',
      is_show_reward_menu: 0, // 是否展示我的奖品按钮
      p: 1,
      loading: false,
      error: false,
      finished: false
    }
  },
  methods: {
    JumpName(name, data) {
      this.$JumpName(this, name, data)
    },
    init() {
      const query = this.$route.query
      this.order_id = query.order_id
      this.group_shopping_id = query.group_shopping_id
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      this.p = 1
      this.loading = false
      this.finished = false
      this.list = []
      this.onLoad()
    },
    onLoad() {
      const params = {
        order_id: this.order_id,
        group_shopping_id: this.group_shopping_id,
        p: this.p
      }
      groupRewardLog(params).then(res => {
        this.loading = false
        this.$loadingWrap.close()
        if (res.status == 1) {
          const resData = res.data
          if (this.p == 1) {
            this.total = resData.total
            this.is_show_reward_menu = resData.is_show_reward_menu
          }
          if (resData.list.length > 0) {
            this.list.push(...resData.list)
            this.p++
            // 第二页自动触发，防止10条高度不够一屏
            if (this.p == 2) {
              this.onLoad()
            }
          } else {
            this.finished = true
          }
        } else {
          this.$Error(res.msg)
        }
      })
    }
  },
  created() {
    this.init()
  },
  mounted() {
    // 小程序触底加载更多
    window.addEventListener('reachbottom', () => {
      this.onLoad()
    })
  },
  beforeCreate() {
    $('body').addClass('bg_white')
  },
  destroyed() {
    $('body').removeClass('bg_white')
  }
})

</script>
<style lang="scss">
.group-prize-container{
  padding-bottom:100px;
  .group-prize-total{
    height: 68px;
    line-height:68px;
    font-size:28px;
    text-align:center;
    color:#F30C23;
    background: rgba(243, 12, 35, 0.05);
    .num{
      font-weight:bold;
    }
  }
  .group-prize-list{
    padding:0 30px;
    .item{
      display:flex;
      align-items: center;
      padding:24px 0;
      border-bottom: 2px solid #EDEDED;
      .item-img{
        overflow:hidden;
        width:70px;
        height:70px;
        border-radius:50%;
        img{
          display:block;
          width:100%;
          height:100%;
        }
      }
      .item-name{
        flex:1;
        margin-left:20px;
        font-size:28px;
        color:#333;
      }
    }
  }
  .btn-box{
    position:fixed;
    left:0;
    bottom:0;
    width:100%;
    height:100px;
    padding:12px 24px 0;
    background:#fff;
    .btn-prize{
      height:76px;
      line-height:76px;
      border-radius: 40px;
      font-size:28px;
      text-align:center;
      color:#fff;
      background: linear-gradient(270deg, #E90104 0%, #FE1B49 100%, #FE1B49 100%);
    }
  }
}
</style>
